package com.kanas.webak.rbac.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import com.kanas.framework.support.AbstractModel;
import com.kanas.framework.util.StringUtils;

@Entity
@Table(name = "kanas_rbac_role_permission")
@JsonIgnoreProperties({"role"})
public class AppPermission extends AbstractModel{

	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name = "id")
	private String id;
	
	@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
	@JoinColumn(name="role_id",referencedColumnName="id")
	private AppRole role;
	
	@Column(name = "permission_id")
	private String permissionId;
	
	@Transient
	private String roleLabel;
	@Transient
	private String permissionName;
	@Transient
	private Boolean checked;
	
	public AppPermission(){
		this.id=StringUtils.generateUUID();
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public AppRole getRole() {
		return role;
	}

	public void setRole(AppRole role) {
		this.role = role;
	}

	public String getPermissionId() {
		return permissionId;
	}

	public void setPermissionId(String permissionId) {
		this.permissionId = permissionId;
	}

	@Override
	public String toIdString() {
		return id;
	}

	public String getRoleLabel() {
		if(roleLabel == null) roleLabel = "";
		return roleLabel;
	}

	public void setRoleLabel(String roleLabel) {
		this.roleLabel = roleLabel;
	}

	public String getPermissionName() {
		if(permissionName == null) permissionName = "";
		return permissionName;
	}

	public void setPermissionName(String permissionName) {
		this.permissionName = permissionName;
	}

	public Boolean getChecked() {
		if(checked == null) checked = false;
		return checked;
	}

	public void setChecked(Boolean checked) {
		this.checked = checked;
	}

}
